package lab03.test01;

import java.io.*;

public class Test {
    public static void main(String[] args) throws FileNotFoundException {
        /**
         * 度一个文件并打印文件内容
         *
         */
        String path = "D:\\hello.txt";
        //1.字符流来读
        //1.1一次读一行
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(path));
            String line = "";
            while ((line = reader.readLine()) != null) {
                //line = reader.readLine();
                System.out.println(line);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //2.字节流来读
        //字节流写文件
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(path);
            fileOutputStream.write(65);
            byte a;
            byte[] data = new byte[3];
            data[0] = 65;
            data[1] = 66;
            data[2] = 67;
            fileOutputStream.write(data);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(path);
            int data;
            while ((data = fileInputStream.read()) != -1){
                System.out.println(data);

        }
    } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
